import { h, resolveComponent } from 'vue'
import { createRouter, createWebHashHistory } from 'vue-router'

import DefaultLayout from '@/layouts/DefaultLayout'

const routes = [
  {
    path: '/',
    name: '一张网调度',
    component: DefaultLayout,
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: '调度总览',
        component: () =>
          import(
            '@/views/dashboard/Dashboard.vue'
          ),
      },
      {
        path: '/theme/workManship',
        name: '厂站工艺',
        component: () =>
          import(
            '@/views/theme/workManship.vue'
          ),
      },
      {
        path: '/theme',
        name: 'Theme',
        redirect: '/theme/typography',
        children: [
          {
            path: '/theme/AlarmIedger',
            name: 'AlarmIedger',
            component: () => import('@/views/theme/AlarmIedger.vue'),
          }, {
            path: '/theme/AlarmRecord',
            name: 'AlarmRecord',
            component: () => import('@/views/theme/AlarmRecord.vue'),
          },
        ],
      },
      {
        path: '/theme/colors',
        name: 'Colors',
        component: () => import('@/views/theme/Colors.vue'),
      },
      {
        path: '/theme/Remote',
        name: 'Remote',
        component: () => import('@/views/theme/Remote.vue'),
      },
      {
        path: '/theme/typography',
        name: 'Typography',
        component: () => import('@/views/theme/Typography.vue'),
      },
      {
        path: '/theme/ProgramManage',
        name: 'ProgramManage',
        component: () => import('@/views/theme/ProgramManage.vue'),
      },
    ],
  },
  {
    path: '/login',
    name: '登录',
    component: () =>
      import(
        '@/views/login.vue'
      ),
  },
  {
    path: '/websocket',
    name: '通信',
    component: () =>
      import(
        '../components/WebSocket.vue'
      ),
  },
  {
    path: '/pages',
    redirect: '/pages/404',
    name: 'Pages',
    component: {
      render() {
        return h(resolveComponent('router-view'))
      },
    },
    children: [
      {
        path: '404',
        name: 'Page404',
        component: () => import('@/views/pages/Page404'),
      },
      {
        path: '500',
        name: 'Page500',
        component: () => import('@/views/pages/Page500'),
      },
      {
        path: 'login',
        name: 'Login',
        component: () => import('@/views/pages/Login'),
      },
      {
        path: 'register',
        name: 'Register',
        component: () => import('@/views/pages/Register'),
      },
    ],
  },
]

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes,
  scrollBehavior() {
    return { top: 0 }
  },
})

export default router
